home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / TEMP / GNU / flex / Generateds < prev    next >
Text File  |  1995-06-28  |  5KB  |  119 lines

  1. Generated scanner
  2. Previous: <Actions=>Actions> * Next: <Start conditions=>Startcondi> * Up: <Top=>!Root>
  3.  
  4. #Wrap on
  5. {fH3}The generated scanner{f}
  6.  
  7. The output of {fCode}flex{f} is the file {fCite}lex.yy.c{f}, which contains
  8. the scanning routine {fEmphasis}yylex(){f}, a number of tables used by
  9. it for matching tokens, and a number of auxiliary routines
  10. and macros.  By default, {fEmphasis}yylex(){f} is declared as follows:
  11.  
  12. #Wrap off
  13. #fCode
  14. int yylex()
  15.     \{
  16.     … various definitions and the actions in here …
  17.     \}
  18. #f
  19. #Wrap on
  20.  
  21. (If your environment supports function prototypes, then it
  22. will be "int yylex( void  )".)   This  definition  may  be
  23. changed by defining the "YY\_DECL" macro.  For example, you
  24. could use:
  25.  
  26. #Wrap off
  27. #fCode
  28. \#define YY\_DECL float lexscan( a, b ) float a, b;
  29. #f
  30. #Wrap on
  31.  
  32. to give the scanning routine the name {fCode}lexscan{f}, returning a
  33. float, and taking two floats as arguments.  Note that if
  34. you give arguments to the scanning routine using a
  35. K&R-style\/non-prototyped function declaration, you must
  36. terminate the definition with a semi-colon ({fEmphasis};{f}).
  37.  
  38. Whenever {fEmphasis}yylex(){f} is called, it scans tokens from the
  39. global input file {fCode}yyin{f} (which defaults to stdin).  It
  40. continues until it either reaches an end-of-file (at which
  41. point it returns the value 0) or one of its actions
  42. executes a {fCode}return{f} statement.
  43.  
  44. If the scanner reaches an end-of-file, subsequent calls are undefined
  45. unless either {fCode}yyin{f} is pointed at a new input file (in which case
  46. scanning continues from that file), or {fEmphasis}yyrestart(){f} is called.
  47. {fEmphasis}yyrestart(){f} takes one argument, a {fEmphasis}FILE \*{f} pointer (which
  48. can be nil, if you've set up {fCode}YY\_INPUT{f} to scan from a source
  49. other than {fCode}yyin{f}), and initializes {fCode}yyin{f} for scanning from
  50. that file.  Essentially there is no difference between just assigning
  51. {fCode}yyin{f} to a new input file or using {fEmphasis}yyrestart(){f} to do so;
  52. the latter is available for compatibility with previous versions of
  53. {fCode}flex{f}, and because it can be used to switch input files in the
  54. middle of scanning.  It can also be used to throw away the current
  55. input buffer, by calling it with an argument of {fCode}yyin{f}; but
  56. better is to use {fCode}YY\_FLUSH\_BUFFER{f} (see above).  Note that
  57. {fEmphasis}yyrestart(){f} does {fEmphasis}not{f} reset the start condition to
  58. {fCode}INITIAL{f} (see Start Conditions, below).
  59.  
  60.  
  61. If {fEmphasis}yylex(){f} stops scanning due to executing a {fCode}return{f}
  62. statement in one of the actions, the scanner may then be called
  63. again and it will resume scanning where it left off.
  64.  
  65. By default (and for purposes of efficiency), the scanner
  66. uses block-reads rather than simple {fEmphasis}getc(){f} calls to read
  67. characters from {fCode}yyin{f}.  The nature of how it gets its input
  68. can be controlled by defining the {fCode}YY\_INPUT{f} macro.
  69. YY\_INPUT's calling sequence is
  70. "YY\_INPUT(buf,result,max\_size)".  Its action is to place
  71. up to {fStrong}max\_size{f} characters in the character array {fStrong}buf{f} and
  72. return in the integer variable {fStrong}result{f} either the number of
  73. characters read or the constant YY\_NULL (0 on Unix
  74. systems) to indicate EOF.  The default YY\_INPUT reads from
  75. the global file-pointer "yyin".
  76.  
  77. A sample definition of YY\_INPUT (in the definitions
  78. section of the input file):
  79.  
  80. #Wrap off
  81. #fCode
  82. %\{
  83. \#define YY\_INPUT(buf,result,max\_size) \\
  84.     \{ \\
  85.     int c = getchar(); \\
  86.     result = (c == EOF) ? YY\_NULL : (buf[0] = c, 1); \\
  87.     \}
  88. %\}
  89. #f
  90. #Wrap on
  91.  
  92. This definition will change the input processing to occur
  93. one character at a time.
  94.  
  95. When the scanner receives an end-of-file indication from
  96. YY\_INPUT, it then checks the {fEmphasis}yywrap(){f} function.  If
  97. {fEmphasis}yywrap(){f} returns false (zero), then it is assumed that the
  98. function has gone ahead and set up {fCode}yyin{f} to point to
  99. another input file, and scanning continues.  If it returns
  100. true (non-zero), then the scanner terminates, returning 0
  101. to its caller.  Note that in either case, the start
  102. condition remains unchanged; it does {fEmphasis}not{f} revert to {fCode}INITIAL{f}.
  103.  
  104. If you do not supply your own version of {fEmphasis}yywrap(){f}, then you
  105. must either use {fEmphasis}%option noyywrap{f} (in which case the scanner
  106. behaves as though {fEmphasis}yywrap(){f} returned 1), or you must link with
  107. {fEmphasis}-lfl{f} to obtain the default version of the routine, which always
  108. returns 1.
  109.  
  110. Three routines are available for scanning from in-memory
  111. buffers rather than files: {fEmphasis}yy\_scan\_string(){f},
  112. {fEmphasis}yy\_scan\_bytes(){f}, and {fEmphasis}yy\_scan\_buffer(){f}.  See the discussion
  113. of them below in the section Multiple Input Buffers.
  114.  
  115. The scanner writes its {fEmphasis}ECHO{f} output to the {fCode}yyout{f} global
  116. (default, stdout), which may be redefined by the user
  117. simply by assigning it to some other {fCode}FILE{f} pointer.
  118.  
  119.